package com.bookstore.dao.imp;

import com.bookstore.bean.TradeItem;
import com.bookstore.dao.TradeItemDao;

import java.util.*;

/**
 * Created by Admin on 2016/8/27.
 */
public class TradeItemDaoImp extends BaseDao<TradeItem> implements TradeItemDao {
    @Override
    public void batchSave(Collection<TradeItem> items) {
        String sql="insert into tradeitem (bookId,quantity,tradeId) values (?,?,?)";
        Object[][] params=null;
        params=new Object[items.size()][3];
        List<TradeItem> tradeItems=new ArrayList<>(items);
        for(int i=0;i< items.size();i++){
            params[i][0]=tradeItems.get(i).getBookId();
            params[i][1]=tradeItems.get(i).getQuantity();
            params[i][2]=tradeItems.get(i).getTradeId();
        }
        batch(sql,params);
    }

    @Override
    public Set<TradeItem> getTradeItemsWithTradeId(Integer tradeId) {
        String sql="select itemId,bookId,quantity,tradeId from tradeitem where tradeId=?";
        Set<TradeItem> set=new HashSet<>(getForList(sql,tradeId));
        return set;
    }
}
